import http, {token} from './http';
import {
	SCAN_CODE_ADD_BAG_URL,
	SCAN_CODE_GOODS_INFO_URL,
	SCAN_CODE_ADD_GOODS_URL,
	SCAN_CODE_DELETE_GOODS_URL,
	SCAN_CODE_UPDATE_GOODS_URL,
	SCAN_CODE_GET_GOODS_URL,
	SCAN_CODE_ORDER_LIST_URL,
	SCAN_CODE_ORDER_DETAIL_URL,
} from './url.js'

// 获取扫码购商品的详细信息
const getScanCodeGoodsInfo = (goodsBarcode, storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_GOODS_INFO_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"storeNo": "133",
				"goodsBarcode": goodsBarcode
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getScanCodeGoodsInfo-err---', err)
	})
}

// 扫码购添加商品
const addScanCodeGoods = (goodsSn, goodsBarcode, count, storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_ADD_GOODS_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"storeNo": "133",
				"goodsSn": goodsSn,
				"goodsBarcode": goodsBarcode,
				"count": count
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('addScanCodeGoods-err---', err)
	})
}

// 扫码购删除商品
const deleteScanCodeGoods = (itemIdStr, storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_DELETE_GOODS_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"storeNo": "133",
				"itemId": itemIdStr
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('deleteScanCodeGoods-err---', err)
	})
}

// 扫码购更新/修改商品
const updateScanCodeGoods = (itemId, count, storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_UPDATE_GOODS_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"storeNo": "133",
				"itemId": itemId,
				"count": count
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('updateScanCodeGoods-err---', err)
	})
}

// 扫码购查看/获取所有商品
const getScanCodeGoods = (storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_GET_GOODS_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"storeNo": "133",
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getScanCodeGoods-err---', err)
	})
}

// 扫码购添加购物袋
const addScanCodeBag = (bigBagCount, smallBagCount, storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_ADD_BAG_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"storeNo": "133",
				"bigBagCount": bigBagCount,
				"smallBagCount": smallBagCount,
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('addScanCodeBag-err---', err)
	})
}

// 获取扫码购所有订单
const getScanCodeOrderList = (lastId, storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_ORDER_LIST_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"status": 0,
				"pageSize": 10,
				"lastId": lastId,
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getScanScanCodeOrderList-err---', err)
	})
}

// 获取扫码购订单详情
const getScanCodeOrderDetail = (storeNo) => {
	return http({
		method: 'post',
		url: SCAN_CODE_ORDER_DETAIL_URL,
		data: {
			"appId": 1005,
			"apiVersion": "7.0",
			"userToken": token,
			"userId": 3644328,
			"storeNo": "133",
			"data": {
				"accountNo": "2009010001045"
			}
		}
	}).then(res => {
		return res
	}).catch(err => {
		console.log('getScanScanCodeOrderDetail-err---', err)
	})
}

export {
	getScanCodeGoodsInfo, 
	addScanCodeGoods,
	deleteScanCodeGoods,
	updateScanCodeGoods,
	getScanCodeGoods,
	addScanCodeBag,
	getScanCodeOrderList,
	getScanCodeOrderDetail
}